// var parameter = getRequest();
// var username = parameter['username'];//参数名
// var userID = parameter['userID'];//参数名
// var openid = parameter['openid'];//参数名

var openid,unionId,usersid,username;


$(function () {

let Strdata = window.sessionStorage.getItem("data");
     // usersid= localStorage.getItem("usersid");
     // username = localStorage.getItem("username");

if (isNull(Strdata,0)==0){
    returnSignin()  //退出登录
}else{

    openid=Strdata.split(',')[0];
    unionId= Strdata.split(',')[1];
    username = Strdata.split(',')[2];

    // $("#username").value(username);
    document.getElementById('username').innerHTML ='用户名：'+isNull(username,'空');

    // $('#RCname').html(RCName);  //填充厂名
    // $("#RCname").text(RCName);
}

});




//打开标签页
function OPENHTML(vStr) {

    switch (vStr) {

        case '门卫管理访单':
            addTab('门卫管理访单','main/html/showavisitor_guard.html?unionId='+ unionId);
            // if (determineQX(vStr,'pview')){
            //     addTab('门卫管理访单','main/html/OrderBill/purchase.html?openID=0');
            // }else {
            //     $.messager.alert('提示', '当前登录账号无权限查看！');
            // }
            break;

        case '访单综合管理':
            addTab('访单综合管理','main/html/showavisitor_sum.html?unionId='+ unionId);
            // if (determineQX(vStr,'pview')){
            //     addTab('访单综合管理','main/html/OrderBill/ExamQuestionBank.html');
            // }else {
            //     $.messager.alert('提示', '当前登录账号无权限查看！');
            // }
            break;

        case '访客资料':
            addTab('访客资料','main/html/showavisitor_client.html?unionId='+ unionId);
            // if (determineQX(vStr,'pview')){
            //     addTab('访单综合管理','main/html/OrderBill/ExamQuestionBank.html');
            // }else {
            //     $.messager.alert('提示', '当前登录账号无权限查看！');
            // }
            break;



    }

}

//注销登录
function returnSignin() {
    var URL= "index.html";

    localStorage.clear();  //清空 local Storage 存放的所有数据

    window.location.replace(URL+window.location.search);
}

//修改密码
function updatepaw() {
    $('#A').window('open');
    $("#A_paw").passwordbox('setValue', '');
    $("#A_pawnew").passwordbox('setValue', '');
}

function savepaw(){
    var paw=$("#A_paw").textbox('getValue');
    var pawnew=$("#A_pawnew").textbox('getValue');
    var A_pawnewCF=$("#A_pawnewCF").textbox('getValue');
    if(A_pawnewCF != pawnew){
        $.messager.alert('提示', '新密码两次录入不一致，无法修改！');
        return;
    }
    $.ajax({
        url: strLin + "sysUser/selectAll",
        type: 'post',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let userdata=cdata.data;
            let result = userdata.filter(function(item) {return item.sid === Strusersid && item.pwd === paw});

            if (result.length>0){
                //参数大于0表示修改
                var SQL={iid:result[0].iid,'pwd':pawnew};
                $.ajax({
                    url: strLin + "sysUser/updateByPrimaryKeySelective",
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(SQL),
                    // data:SQL,
                    contentType: "application/json;charset=UTF-8",
                    success: function (data) {
                        // alert('修改成功！');
                        if (data.code != 1){
                            $.messager.alert('提示', data.msg);
                            return;
                        }else {
                            $.messager.show({title:'我的消息', msg:'密码修改成功'});
                            $('#A').window('close')
                        }
                    }
                });

            }else{
                $.messager.show({title:'我的消息', msg:'原密码错误'});
            }




        }
    });


}

$.extend($.fn.tabs.methods,{
    allTabs:function(jq){
        var tabs = $(jq).tabs('tabs');
        var all = [];
        all = $.map(tabs,function(n,i){
            return $(n).panel('options')
        });
        return all;
    },
    closeCurrent: function(jq){ // 关闭当前
        var currentTab = $(jq).tabs('getSelected'),
            currentTabIndex = $(jq).tabs('getTabIndex',currentTab);
        $(jq).tabs('close',currentTabIndex);
    },
    closeAll:function(jq){ //关闭全部
        var tabs = $(jq).tabs('allTabs');
        $.each(tabs,function(i,n){
            $(jq).tabs('close', n.title);
        })
    },
    closeOther:function(jq){ //关闭除当前标签页外的tab页
        var tabs =$(jq).tabs('allTabs');
        var currentTab = $(jq).tabs('getSelected'),
            currentTabIndex = $(jq).tabs('getTabIndex',currentTab);

        $.each(tabs,function(i,n){
            if(currentTabIndex != i) {
                $(jq).tabs('close', n.title);
            }
        })
    },
    closeLeft:function(jq){ // 关闭当前页左侧tab页
        var tabs = $(jq).tabs('allTabs');
        var currentTab = $(jq).tabs('getSelected'),
            currentTabIndex = $(jq).tabs('getTabIndex',currentTab);
        var i = currentTabIndex-1;

        while(i > -1){
            $(jq).tabs('close', tabs[i].title);
            i--;
        }
    },
    closeRight: function(jq){ //// 关闭当前页右侧tab页
        var tabs = $(jq).tabs('allTabs');
        var currentTab = $(jq).tabs('getSelected'),
            currentTabIndex = $(jq).tabs('getTabIndex',currentTab);
        var i = currentTabIndex+ 1,len = tabs.length;
        while(i < len){
            $(jq).tabs('close', tabs[i].title);
            i++;
        }
    }
})

function addTab(title, url){
    let Strurl=url+ '?username='+username;
    // let Strurl=url;
    if ($('#tt').tabs('exists', title)){
        $('#tt').tabs('select', title);
    } else {
        var content = '<iframe scrolling="auto" frameborder="0"  src="'+Strurl+'" style="width:100%;height:100%;"></iframe>';
        $('#tt').tabs('add',{
            title:title,
            content:content,
            closable:true,
        });
    }
}

function closeTab() {
    $('#tt').tabs('closeCurrent');
}



//获取浏览器地址参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

//获取浏览器地址参数（参数为中文）
function getRequest() {
    var url = window.location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            //就是这句的问题
            theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
            //之前用了unescape()
            //才会出现乱码
        }
    }
    return theRequest;
}
